<template>
	<div class="form-box">
		<h2 class="title">用户登录</h2>
		<form>
			<div class="form-group">
				<input class="kk" type="text" placeholder="用户名" v-model="user.userName">
			</div>
			<div class="form-group">
				<input class="kk" type="password" placeholder="密码" v-model="user.password">
			</div>
			<div class="form-group">
				<button @click="login" class="kk" type="button">登录</button>
			</div>
		</form>
		<div style="text-align: center;">
			没有账号，去&nbsp;<router-link to="Register">注册</router-link>
		</div>
	</div>
</template>

<script>
	export default {
		data() {
			return {
				user: {
					userName: '',
					password: ''
				},
				returnpath: {
					name: "Home",
				}
			}
		},
		created() {
			var newurl = this.$route.params.urlpath;
			if (newurl) {
				this.returnpath = this.$route.params.urlpath;
			}
			console.log(this.returnpath);
		},
		methods: {
			login() {
				this.axios.post('/login', this.user).then(response => {
					let res = response.data;
					if (res.code == 0) {
						sessionStorage.setItem('newuser', JSON.stringify(res.data));
						this.$router.push(this.returnpath)
						return;
					} else {
						this.$message(res.msg)
					}
				})
			}
		}
	}
</script>

<style scoped="scoped">
	html,
	body {
		height: 100%;
	}

	body {
		background-image: url(../assets/img/register-body-bg.png);
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.form-box {
		width: 450px;
		/* height: 550px; */
		border-radius: 8px;
		background-image: linear-gradient(to bottom, white, #EFEFF0);
		box-shadow: 15px 15px 15px 0px #CCCCCC;
		padding: 40px;
		margin: 0 auto;
	}

	.title {
		border-bottom: 1px solid #CCCCCC;
		padding-bottom: 15px;
		margin: 0px -40px 20px;
		text-align: center;
	}

	.form-group {
		margin-bottom: 20px;
	}

	.kk {
		padding: 10px;
		width: 100%;
	}

	form {
		padding-bottom: 20px;
		margin-bottom: 20px;
		border-bottom: 1px solid #CCCCCC;
	}

	a {
		color: blue;
	}
</style>
